package utils;


import dto.StudentDto;
import pojo.Student;

import java.util.ArrayList;
import java.util.List;

public class DtoUtils {

    public static StudentDto studentDtoHandler(Student student){

        //处理学生的性别数据
        String sex = student.getSex();
        if("man".equals(sex)){
            sex = "男";
        }else if("woman".equals(sex)){
            sex = "女";
        }

        //处理学生的爱好数据
        String hobbies = student.getHobbies();
        hobbies = hobbies.replaceAll("football","足球");
        hobbies = hobbies.replaceAll("basketball","篮球");
        hobbies = hobbies.replaceAll("shop","购物");

        //创建StudentDto
        StudentDto studentDto = new StudentDto(student, sex, hobbies);
        return studentDto;
    }

    public static List<StudentDto> studentDtoListHandler(List<Student> students){

        List<StudentDto> studentDtos = new ArrayList<>();

        for (Student student : students) {
            StudentDto studentDto = studentDtoHandler(student);
            studentDtos.add(studentDto);
        }
        return studentDtos;
    }

}
